package com.sjc.algorithm.leetcode;

import jdk.internal.org.objectweb.asm.tree.MultiANewArrayInsnNode;

/**
 * @author by SangJiacun
 * @Date 2020/5/14 23:39
 */
public class P07 {
    public static void main(String[] args) {
        System.out.println(reverse(123));
    }

    public static int reverse(int x) {
        int y = 0;
        while(x != 0){
            int a = x%10;
            x = x/10;
            if(y > Integer.MAX_VALUE/10 || (y == Integer.MAX_VALUE/10 && a>7)){ return 0; }
            if(y < Integer.MIN_VALUE/10 || (y == Integer.MIN_VALUE/10 && a<-8)){ return 0; }
            y = y*10+a;

        }
        return y;
    }
}
